package com.dup.jxlh.admin.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dup.jxlh.admin.entities.handler.ChapterApplyStatusHandler;
import com.dup.jxlh.admin.entities.handler.ChapterApplyTypeHandler;
import com.dup.jxlh.admin.entities.model.ChapterApply;
import com.dup.jxlh.admin.entities.vo.ChapterApplyVO;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface ChapterApplyMapper extends BaseMapper<ChapterApply> {
    @Select("select chapter_apply.* from chapter_apply ${ew.customSqlSegment}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "attachList",
                    many = @Many(select = "com.dup.jxlh.admin.mapper.ChapterAttachMapper.getChapterAttachList")),
            @Result(column = "id", property = "chapterTypeList",
                    many = @Many(select = "com.dup.jxlh.admin.mapper.ChapterTypeMapper.getChapterTypeList")),
            @Result(column = "id", property = "chapterType",
                    many = @Many(select = "com.dup.jxlh.admin.mapper.ChapterTypeMapper.getChapterType")),

            @Result(column = "type", property = "type"),
            @Result(column = "type", property = "typeName", typeHandler = ChapterApplyTypeHandler.class),

            @Result(column = "status", property = "status"),
            @Result(column = "status", property = "statusName", typeHandler = ChapterApplyStatusHandler.class),

            @Result(column = "department_id", property = "departmentId"),
            @Result(column = "department_id", property = "department",
                    one = @One(select = "com.dup.jxlh.admin.mapper.DepartmentMapper.selectById")),

            @Result(column = "apply_id", property = "applyId"),
            @Result(column = "apply_id", property = "applier",
                    one = @One(select = "com.dup.jxlh.admin.mapper.AdminMapper.selectById")),

            @Result(column = "check_id", property = "checkId"),
            @Result(column = "check_id", property = "checker",
                    one = @One(select = "com.dup.jxlh.admin.mapper.AdminMapper.selectById"))
    })
    ArrayList<ChapterApplyVO> getChapterApplyList(Page page, @Param(Constants.WRAPPER) Wrapper<ChapterApply> wrapper);
}
